#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>

using namespace std;

int year;
char line[300];
bool sorted;

int monthDay[]={31,28,31,30,31,30, 31,31,30,31,30,31};

typedef struct TDate {
	int day, month;
} TDate;

typedef struct TEvent {
	int p;
	int inputOrder;
	TDate date;
	string desc;
} TEvent;

TEvent tempEvent;
TDate date;
vector<TEvent> eventList;
vector<TEvent> forsort;

ostream& operator <<(ostream& out, const TDate& d) {
	if (d.day > 31)
		return out << setw(3) << d.day%31 << setw(3) << 1;
	else
		return out << setw(3) << d.day << setw(3) << d.month;
}

ostream& operator <<(ostream& out, const TEvent& e) {
	return out << e.date << " " << e.p << " " << e.desc;
}

bool operator < (const TDate& a, const TDate& b) {
	if (a.month < b.month) return true;
	if (a.month == b.month && a.day < b.day) return true;
	return false;
}

int operator - (const TDate& a, const TDate& b) {
	int day = 0;
	if (year % 4 == 0) monthDay[1] += 1;
	for (int i=b.month; i<a.month; ++i)
		day += monthDay[i-1];
	day += a.day - b.day;
	if (year % 4 == 0) monthDay[1] -= 1;
	return day;
}

bool operator < (const TEvent& a, const TEvent& b) {
	if (a.date < b.date) return true;
	if (b.date < a.date) return false;
	return (a.inputOrder < b.inputOrder);
}

bool compP (const TEvent& a, const TEvent& b) {
	if (a.p > b.p) return true;
	if (a.p < b.p) return false;
	if (a.date < b.date) return true;
	if (b.date < a.date) return false;
	return (a.inputOrder < b.inputOrder);
}

int main(void)
{
	cin >> year;
	int order = 0;
	sorted = false;

// 	TDate x, y;
// 	x.month = 2;
// 	x.day = 27;
// 	y.month = 2;
// 	y.day = 25;
// 	cout << x << "   " << y << "   " << x - y << endl;

	bool start = true;

	while (true) {
		cin.getline(line, 300);
		if (line[0] == '#') break;
		if (line[0] == 'A') {
			stringstream ss(stringstream::in | stringstream::out);
			ss << line;
			string bufStr;
			ss >> bufStr;
			ss >> tempEvent.date.day >> tempEvent.date.month >> tempEvent.p;
			memset(line, 0, 300);
			ss.getline(line, 300);
			for (int i=0; i<strlen(line); ++i)
				if (line[i] != ' ' && line[i] != '\t') {
					tempEvent.desc = string(&line[i]);
					break;
				}
			tempEvent.inputOrder = order++;
			eventList.push_back(tempEvent);
			if (tempEvent.date.month == 1 && tempEvent.date.day < 8) {
				tempEvent.date.month = 12;
				tempEvent.date.day += 31;
				eventList.push_back(tempEvent);
			}
		}
		else if (line[0] == 'D') {
			if (!start) cout << endl;
			else
				start = false;
			if (sorted == false) {
				sort(eventList.begin(), eventList.end());
				sorted = true;
			}
			stringstream ss(stringstream::in | stringstream::out);
			ss << line;
			string bufStr;
			ss >> bufStr;
			ss >> date.day >> date.month;

			cout << "Today is:" << date << endl;

			tempEvent.date = date;
			tempEvent.p = 10000;
			tempEvent.inputOrder = -1;
			int pos = lower_bound(eventList.begin(), eventList.end(), tempEvent) - eventList.begin();

			forsort.clear();

			for (int i=pos; i<eventList.size(); ++i) {
				if (date < eventList[i].date) {
					int diff = eventList[i].date - date;
					if (diff > 7) break;
					if (1+eventList[i].p-diff <= 0) continue;
					int bakP = eventList[i].p;
					eventList[i].p = 1+eventList[i].p-diff;
					forsort.push_back(eventList[i]);
					eventList[i].p = bakP;
// 					cout << eventList[i].date << " ";
// 					for (int j=0; j<1-diff+eventList[i].p; ++j)
// 						cout << "*";
// 					for (int j=0; j<7+diff-eventList[i].p; ++j)
// 						cout << " ";
// 					cout << eventList[i].desc << endl;

				}
				else {
					cout << date << " *TODAY* " << eventList[i].desc << endl;
				}
			}



			sort(forsort.begin(), forsort.end(), compP);
			for (int i=0; i<forsort.size(); ++i) {
				cout << forsort[i].date << " ";
				for (int j=0; j<forsort[i].p; ++j)
					cout << "*";
				for (int j=0; j<8-forsort[i].p; ++j)
					cout << " ";
				cout << forsort[i].desc << endl;
			}

		}
	}

	return 0;
}